<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'

export default {
  name: "Scroll",
  props: {
    probeType: {
      type: Number,
      default() {
        return 0;
      }
    },
    isPullUpLoad: {
      type: Boolean,
      default() {
        return false;
      }
    }
  },
  data() {
    return {
      scroll: null,
    };
  },
  mounted() {
    this.scroll = new BScroll(this.$refs.wrapper, {
      click: true,
      /*这个属性由外界觉顶，默认0*/
      probeType: this.probeType,
      useTransition: true,
      pullUpLoad: this.isPullUpLoad,
    });
    if (this.probeType === 2 || this.probeType === 3) {
      this.scroll.on('scroll', p => {
        this.$emit('scrollPosition', p);
      });
    }
    if (this.isPullUpLoad) {
      this.scroll.on('pullingUp', () => {
        this.$emit('pullUpLoad',);
      });
    }
  },
  methods: {
    scrollTo(x, y, time = 500) {
      this.scroll && this.scroll.scrollTo(x, y, time);
    },
    refresh() {
      this.scroll && this.scroll.refresh();
    },
    finishPullUp() {
      this.scroll && this.scroll.finishPullUp();
    }
  }
}
</script>

<style scoped>
</style>
